home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / wgt / wgttply2 / testpoly.c < prev   
C/C++ Source or Header  |  1994-08-02  |  2KB  |  122 lines

  1. #include <wgt4.h>
  2. #include <math.h>
  3.  
  4.  
  5. tpolypoint mypoints[4];
  6. tpolypoint rotpoints[4];
  7.  
  8. color pal[256];
  9. block text;
  10. long isin[360],icos[360];
  11.  
  12. int rot;
  13. int i, px,py;
  14. int zdir=0;
  15. int xzoom=0;
  16. int yzoom=0;
  17.  
  18. int rotspeed = 2, rotdir=1;
  19.  
  20.  
  21. void make_sin_cos_tables(void)
  22. {
  23. int i;
  24.  
  25.  for (i=0; i<360; i++)
  26.  {
  27.  isin[i]=sin(3.1415*((double)i/180.0))*1024;
  28.  icos[i]=cos(3.1415*((double)i/180.0))*1024;
  29.  }
  30. }
  31.  
  32. void rotatetext(int centx, int centy, tpolypoint *mypoly, tpolypoint *mypoly2,
  33.                 int rot)
  34. {
  35. int i;
  36. int x,y;
  37. int x2,y2;
  38.  
  39. for (i=0; i<4; i++)
  40.   {
  41.    x=mypoly[i].x-centx;
  42.    y=mypoly[i].y-centy;
  43.  
  44.   x2 = ((long)x * icos[rot] - (long)y * isin[rot])>>10;
  45.   y2 = ((long)x * isin[rot] + (long)y * icos[rot])>>10;
  46.   mypoly2[i].x=x2+centx;
  47.   mypoly2[i].y=y2+centy;
  48.   }
  49. }
  50.  
  51.  
  52. void main(void)
  53. {
  54.  
  55. vga256();
  56.  
  57. make_sin_cos_tables();
  58.  
  59. mypoints[0].x = 0;
  60. mypoints[0].y = 0;
  61. mypoints[1].x = 128;
  62. mypoints[1].y = 0;
  63. mypoints[2].x = 128;
  64. mypoints[2].y = 128;
  65. mypoints[3].x = 0;
  66. mypoints[3].y = 128;
  67.  
  68. mypoints[0].sx = 0;
  69. mypoints[0].sy = 0;
  70. mypoints[1].sx = 319;
  71. mypoints[1].sy = 0;
  72. mypoints[2].sx = 319;
  73. mypoints[2].sy = 199;
  74. mypoints[3].sx = 0;
  75. mypoints[3].sy = 199;
  76.  
  77. minit();
  78. msetbounds(0,0,191,119);
  79.  
  80. wsetpalette(0,255,pal);
  81. text = wloadblock("wgt1.blk");
  82. wloadpalette("wgt1.pal",pal);
  83. wputblock(0,0,text,0);
  84. wfreeblock(text);
  85.  
  86. text = wnewblock(0,0,319,199);
  87. wcls(0);
  88. wsetpalette(0,255,pal);
  89.  
  90. rot = 0;
  91. minit();
  92. do {
  93.  
  94.  if (but == 1)
  95.    {
  96.     rot -=rotspeed;
  97.     if (rot < 0)
  98.       rot +=360;
  99.    }
  100.  if (but == 2)
  101.    {
  102.     rot +=rotspeed;
  103.     if (rot >359)
  104.       rot -=360;
  105.    }
  106.  
  107.  rotatetext(64,64, mypoints, rotpoints, rot);
  108.  
  109.  for (i = 0; i < 4; i++)
  110.    {
  111.    rotpoints[i].sx = mypoints[i].sx;
  112.    rotpoints[i].sy = mypoints[i].sy;
  113.    }
  114.  wtexturedpoly(rotpoints, 4, mx-32, my-32, text, 0);
  115.  
  116.  } while (!kbhit());
  117.  
  118. wfreeblock(text);
  119. wsetmode(3);
  120.  
  121. }
  122.